﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Xml.Linq;
using RuleCode.Table;

namespace map.member
{
    public partial class designshop_head : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                dealrequest();
                cbshoppageelement spe = cbshoppageelement.findorcreatesystem(AliApi.appUserId,
                 "招牌栏目");
                Fck_Content.Value = Server.HtmlDecode(spe.cbcode.ToString());
                DropDownList_width.Text = spe.width.ToString();
                DropDownList_height.Text = spe.height.ToString();
                TextBox1.Text = spe.backcolour.ToString();
                //TextBox2.Text = spe.backpicpath.ToString();
                DropDownList1.Text = spe.repeat.ToString();
            }
        }

        private void dealrequest()
        {
            cbuser.dealcookie();
            if (AliApi.appUserId == "")
            {
                Response.Redirect(ResolveUrl("~/member/login.aspx") + "?redirecturl=" + this.Request.Url);
            }
        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            preview();
        }

        private void preview()
        {
            cbshoppageelement spe = cbshoppageelement.findorcreatesystem(AliApi.appUserId,
                "招牌栏目");
            spe.cbcode.Value = Fck_Content.Value;
            spe.width.Value = DropDownList_width.Text;
            spe.height.Value = DropDownList_height.Text;
            spe.backcolour.Value = TextBox1.Text;
            //spe.backpicpath.Value = TextBox2.Text;
            spe.repeat.Value = DropDownList1.Text;
            Literal1.Text = spe.gethtml0(1);        
        }

        protected void Button_save_Click(object sender, EventArgs e)
        {
            preview();
            cbshoppageelement spe = cbshoppageelement.findorcreatesystem(AliApi.appUserId,
                "招牌栏目");
            spe.cbcode.Value = Fck_Content.Value;
            spe.width.Value = DropDownList_width.Text;
            spe.height.Value = DropDownList_height.Text;
            spe.backcolour.Value = TextBox1.Text;
            //spe.backpicpath.Value = TextBox2.Text;
            spe.repeat.Value = DropDownList1.Text;
            spe.Modify();
            MessageBox.Show(this.Page, "保存完毕");
        }

        protected void DropDownList_height_SelectedIndexChanged(object sender, EventArgs e)
        {
            int i = zfunction.str2int(DropDownList_height.Text);
            if (i == 0)
                i = 100;
            Fck_Content.Height = i + 76;
            Button1_Click(null, EventArgs.Empty);
        }
        protected void Button_shangchuan_Click(object sender, EventArgs e)
        {
            string strImg2 = FileUpload_img.FileName.Substring(FileUpload_img.FileName.LastIndexOf(".") + 1);
            string time2 = DateTime.Now.ToString("yyyyMMddhhmmss") + "." + strImg2;
            string strFilePth = Server.MapPath(@"~/file/") + time2;
            string linkpth = ResolveUrl(@"~/file/") + time2;
            if (FileUpload_img.HasFile)
            {
                FileUpload_img.SaveAs(strFilePth);
                cbshoppageelement spe = cbshoppageelement.findorcreatesystem(AliApi.appUserId,
                    "招牌栏目");
                spe.backpicpath.Value = linkpth;
                spe.Modify();
                preview();
                MessageBox.Show(this.Page, "保存完毕");
            }

        }

        protected void Button_qingchu_Click(object sender, EventArgs e)
        {
            cbshoppageelement spe = cbshoppageelement.findorcreatesystem(AliApi.appUserId,
                "招牌栏目");
            spe.backpicpath.Value = "";
            spe.Modify();
            preview();
            MessageBox.Show(this.Page, "保存完毕");
        }
    }
}
